﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;

using Spring.Context.Support;
using Spring.ServiceModel;

using Common.Logging;

using log4net.Config;

namespace SpringNETAS
{
    public partial class SpringNETAS : ServiceBase
    {
        //Spring AS Service Name
        private const string SPRING_NET_AS_NAME = "SpringNETAS";
        private static readonly ILog LOG = LogManager.GetLogger(typeof(SpringNETAS));

        public SpringNETAS()
        {
            InitializeComponent();

            //Set Service Name
            this.ServiceName = SPRING_NET_AS_NAME;            
        }

        protected override void OnStart(string[] args)
        {
            try
            {
                // Using Spring's IoC container. Force Spring to load configuration
                ContextRegistry.GetContext();

                //Initialize Log4Net logger Service
                XmlConfigurator.Configure();

                LOG.Info("Spring NET AS is opened!");
            }
            catch (Exception ex)
            {
                LOG.Error("Spring NET AS is broken!", ex);
            }

        }
        protected override void OnStop()
        {
            LOG.Info("Spring NET AS is closed!");
        }
    }
}
